package com.doit;

import org.apache.zookeeper.ZooKeeper;

import java.util.List;

/**
 * @DATE 2021/12/10/15:52
 * @Author MDK
 * @Version 2021.2.2
 *  获取指定节点下子节点和子节点的值
 *
 **/
public class C02_Demo02 {
    public static void main(String[] args) throws Exception{
        ZooKeeper zk = new ZooKeeper("linux01:2181,linux02:2181,linux03:2181",2000,null);
        //获取指定路径下的子节点
        List<String> children = zk.getChildren("/", null);
        for (String child : children) {
            //打印子节点的名字 获取每个子节点的值
            byte[] data = zk.getData("/" + child, null, null);
            System.out.println("/"+child+"节点的值为:"+new String(data));
        }
        zk.close();
    }
}
